/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "TestDatabase.h"

#include "myassert.h"
#include "Error.h"

#include "MudPlayer.h"

using namespace Chronos;
using namespace std;

TestDatabase::TestDatabase() : lastQuery("") {
    addPlayer("player", "player123");
}


bool TestDatabase::hasPlayer(const string& name) {
    PlayersIter iter = players.find(name);
    return (iter != players.end());
}


bool TestDatabase::checkPasswd(const string& name, const string& passwd) {
    PlayersIter iter = players.find(name);
    ASSERT_FALSE(iter == players.end());
    return (passwd == iter->second); 
}


void TestDatabase::addPlayer(const string& name, const string& password) {
    ASSERT_TRUE(players.find(name) == players.end());
    players[name] = password;
}


void TestDatabase::query(const char* str) {
    lastQuery = str;
}

void TestDatabase::query(const char* str, Result& result) {
    lastQuery = str;
    result.add("1");    // id
    result.add("");     // stats
    result.add("");     // inventory
    result.add("");     // equipment
    result.add("1");    // credits
}

void TestDatabase::savePlayerAttribute(int, const char*, const string&) {}

string TestDatabase::getPlayerAttribute(int, const char*) { return ""; }

int TestDatabase::getPlayerIntAttribute(int, const char*) { return 0; }

